#include <bits/stdc++.h>
using namespace std;
typedef int ElemType;

typedef struct SqList {
    ElemType *data;
    int length;

    SqList() {
        this->data = nullptr;
        this->length = 0;
    }

    SqList(ElemType *head, int length) {
        for (int i = 0; i < length; i++) {
            this->data[i] = head[i];
        }
        this->length = length;
    }

    ~SqList() {
        for (int i = 0; i < this->length; i++) {
            delete (this->data + i);
        }
        this->data = nullptr;
        this->length = 0;
    }

    void Print() {
        std::cout << "Data :" << std::endl;
        for (int i = 0; i < this->length; i++) {
            std::cout << this->data[i];
            std::cout << " ";
        }
        std::cout << std::endl;
        std::cout << "Length : " << this->length << std::endl;
    }

    int GetLength() {
        return this->length;
    }

    ElemType GetElem(int pos) {
        return this->data[pos];
    }

    int LocaleElem(ElemType val) {
        for (int i = 0; i < this->length; i++) {
            if (this->data[i] == val) {
                return i;
            }
        }
        return -1;
    }

    bool Insert(int pos, ElemType val) {
        if (pos < 0 || pos >= this->length) return false;
        this->length++;
        for (int i = this->length - 1; i > pos; i--) {
            this->data[i] = this->data[i - 1];
        }
        this->data[pos] = val;
        return true;
    }

    bool Modify(int pos, ElemType val) {
        if (pos < 0 || pos >= this->length) return false;
        this->data[pos] = val;
        return true;
    }

    bool Delete(int pos) {
        if (pos < 0 || pos >= this->length) return false;
        for (int i = pos; i < this->length - 1; i++) {
            this->data[i] = this->data[i + 1];
        }
        this->length--;
        return true;
    }

    bool Empty() {
        return this->length == 0;
    }

} SqListLiner;

int main() {
    cout << "顺序表" << endl;
    ElemType a[10] = {1, 3, 5, 2, 4, 7, 6, 9, 8, 0};
    SqListLiner *sq = new SqListLiner(a, 10);
    sq->Print();
    sq->Modify(4, 12);
    sq->Print();
    sq->Insert(6, 38);
    sq->Print();
    sq->Delete(8);
    sq->Print();
    cout << sq->GetElem(2) << endl;
    cout << sq->LocaleElem(7) << endl;
    cout << sq->LocaleElem(11) << endl;
    cout << sq->GetLength() << endl;
    cout << sq->Empty() << endl;
    return 0;
}